package com.wgc.goods.controller;

import com.wgc.entity.Result;
import com.wgc.goods.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * 商品
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService iProductService;
    /**
     * 审核
     * @param id
     * @return
     */
    @PostMapping("/audit")
    public Result audit(@RequestParam Long id, @RequestParam Integer audit){
        Integer i = iProductService.audit(id,audit);
        if (i == -1) {
            return Result.fail("审核失败");
        }
        if (i == 2){
            return Result.fail("审核拒绝");
        }
        return Result.ok("审核成功");
    }
    /**
     * 上、下架
     * @param id
     * @return
     */
    @PostMapping("/status")
    public Result status(@RequestParam Long id,@RequestParam Integer status){
        Integer i = iProductService.status(id,status);
        if (i != 1) {
            return Result.fail("上下架失败");
        }
        if (status == 0){
            return Result.ok("下架成功");
        }
        return Result.ok("上架成功");
    }

}
